import sys

from pdf2docx import Converter
import os
def getFilesList(type='docx'):
    current_directory = os.getcwd()
    all_items = os.listdir(current_directory)
    files = [item for item in all_items if item.endswith(type) and not item.startswith('~')]
    return files

lst = getFilesList('pdf')

for path in lst:

    pdf_path = "1.pdf"
    docx_path = "1.docx"

    # 创建转换器对象
    cv = Converter(pdf_path)

    # 转换（start=起始页, end=结束页）
    cv.convert(docx_path, start=0, end=None)  # 全部转换

    # 关闭转换器
    cv.close()

    print(f"PDF 已转换为 Word: {docx_path}")